<?php
namespace adminmatrix\plugins;

use adminmatrix\plugins\command\migration\Creator;
use think\App;
use think\Route;
use think\Service as BaseService;
use think\Str;
use think\facade\Config;

use think\Request;

use adminmatrix\plugins\command\PluginsInstall;

use adminmatrix\plugins\command\migration\migrate\Create as PluginsMigrateCreate;
class Service extends BaseService
{
    protected string $plugin_name = 'app';
    use TraitInitRoute;
    public function boot(): void
    {

        $rootPath = $this->app->getRootPath();
        spl_autoload_register(function ($class) use ($rootPath) {
            // 检查是否是插件命名空间
            if (strpos($class, 'plugins\\') === 0) {
                // 将命名空间转换为文件路径
                $path = $rootPath . str_replace('\\', '/', $class) . '.php';
                if (file_exists($path)) {
                    require_once $path;
                    return true;
                }
            }
            return false;
        });

        $this->route();

        $this->app->bind('plugin.migration.creator' , Creator::class);
        $this->commands([
            PluginsInstall::class,


            PluginsMigrateCreate::class
        ]);
    }
}